/*		send_data:function()
		{
			GetCmd	getCmd;
				infoHash[];
			getCmd.info_hash = base64(infoHash);
			getCmd.peer_id = "";
			getCmd.port = 16389;
			getCmd.uploaded = ;
			getCmd.left = ;
			getCmd.compact = ;
			getCmd.compact = ;
		}
*/
class message
{//TLV
public:
	int		cmd_code;
	int		cmd_len;
	union	cmd_body;

public:
	static bool get_rsp_msg(const message* msg_send, message* msg_rsp)
	{
		if (NULL == msg_send || NULL == msg_rsp)
			return false;

		static char res_cmd_buffer[40];
		static int bytes_to_read = 40;//STATIC_INSTANCE(XmpCmdFactory)->max_cmd_header_len();
		int readed = SocketUtil::RecvData(s, res_cmd_buffer, bytes_to_read);

		if(readed != bytes_to_read)
		{
			LOG_WARN("get head: RecvData() failed, try to read " << bytes_to_read << " bytes, but only readed "
				<< readed << " bytes!" << "errorno=" << ::WSAGetLastError());
			return false;
		}

		int remain_len = 40, response_code;
		if (!cmd_ptr->decode_response_code(res_cmd_buffer, remain_len, response_code))
			return false;

		if (response_code != 0)
		{
			LOG_WARN("response code = " << response_code);
			*(int*)rst_ptr = response_code;
			return true;
		}

		readed = SocketUtil::RecvData(s, cmd_buffer, remain_len);
		if(s != INVALID_SOCKET)
		{
			::closesocket(s);
			s = INVALID_SOCKET;
		}

		if(readed != remain_len)
		{
			LOG_WARN("get body: RecvData() failed, try to read " << remain_len << " bytes, but only readed "
				<< readed << " bytes!" << "errorno=" << ::WSAGetLastError());
			return false;
		}

		return cmd_ptr->decode_response(cmd_buffer, remain_len, rst_ptr);
	}
};

class 